package com.dailyblue.java.spring.ioc.demo3;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {

    public static void a() {
        // 加载配置文件
        ApplicationContext beans = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 获取到对象
        Object obj1 = beans.getBean("da"); // 根据对象名获取到对象
        DemoA obj2 = beans.getBean(DemoA.class); // 根据数据类型获取到对象
        DemoA obj3 = beans.getBean("da", DemoA.class); // 根据名称和数据类型获取到对象
        System.out.println(obj1);
        System.out.println(obj2);
        System.out.println(obj3);
    }
    public static void b() {
        // 加载配置文件
        ApplicationContext beans = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 获取到对象
        // DemoB obj2 = beans.getBean(DemoB.class); // 根据数据类型获取到对象 必须在容器中只有一个这个类型对象
        //System.out.println(obj2);
        DemoB obj = beans.getBean("db1",DemoB.class);
        System.out.println(obj);
        DemoC dc = beans.getBean(DemoC.class);
        System.out.println(dc);
        DemoD dd = beans.getBean(DemoD.class);
        System.out.println(dd);
    }
    public static void main(String[] args) {
        a();
    }
}
